package com.qiangshi.web.controller.alarmLog;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.qiangshi.alarmLog.domain.to.QsAlarmLogTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qiangshi.common.annotation.Log;
import com.qiangshi.common.core.controller.BaseController;
import com.qiangshi.common.core.domain.AjaxResult;
import com.qiangshi.common.enums.BusinessType;
import com.qiangshi.alarmLog.domain.QsAlarmLog;
import com.qiangshi.alarmLog.service.IQsAlarmLogService;
import com.qiangshi.common.utils.poi.ExcelUtil;
import com.qiangshi.common.core.page.TableDataInfo;

/**
 * 报警数据Controller
 *
 * @author qiangshi
 * @date 2022-03-08
 */
@RestController
@RequestMapping("/alarmLog/alarmLog")
public class QsAlarmLogController extends BaseController
{
    @Autowired
    private IQsAlarmLogService qsAlarmLogService;

    /**
     * 查询报警数据列表
     */
    @PreAuthorize("@ss.hasPermi('alarmLog:alarmLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(QsAlarmLogTO qsAlarmLog)
    {
        startPage();
        List<QsAlarmLog> list = qsAlarmLogService.selectQsAlarmLogList(qsAlarmLog);
        return getDataTable(list);
    }

    /**
     * 导出报警数据列表
     */
    @PreAuthorize("@ss.hasPermi('alarmLog:alarmLog:export')")
    @Log(title = "报警数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QsAlarmLogTO qsAlarmLog)
    {
        List<QsAlarmLog> list = qsAlarmLogService.selectQsAlarmLogList(qsAlarmLog);
        ExcelUtil<QsAlarmLog> util = new ExcelUtil<QsAlarmLog>(QsAlarmLog.class);
        util.exportExcel(response, list, "报警数据数据");
    }

    /**
     * 获取报警数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('alarmLog:alarmLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(qsAlarmLogService.getById(id));
    }

    /**
     * 新增报警数据
     */
    @PreAuthorize("@ss.hasPermi('alarmLog:alarmLog:add')")
    @Log(title = "报警数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QsAlarmLog qsAlarmLog) {
        return toAjax(qsAlarmLogService.save(qsAlarmLog));
    }

    /**
     * 修改报警数据
     */
    @PreAuthorize("@ss.hasPermi('alarmLog:alarmLog:edit')")
    @Log(title = "报警数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QsAlarmLog qsAlarmLog) {
        return toAjax(qsAlarmLogService.updateById(qsAlarmLog));
    }

    /**
     * 删除报警数据
     */
    @PreAuthorize("@ss.hasPermi('alarmLog:alarmLog:remove')")
    @Log(title = "报警数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(qsAlarmLogService.removeByIds(Arrays.asList(ids)));
    }
}
